/*
 * bsp_rf.h
 *
 *  Created on: 2023年7月4日
 *      Author: zlw
 */

#ifndef BSP_RF_H_
#define BSP_RF_H_

#include "rail.h"
#include "rail_types.h"
#include "stdbool.h"
#include "rail_chip_specific.h"
#include "error_code.h"



/***************************************** 内部使用宏定义、枚举 *******************************************************/
// <e SL_RAIL_UTIL_INIT_EVENTS_INST0_ENABLE> Radio Event Configuration
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENTS_INST0_ENABLE 1
// <h> RX Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_RX_TIMING_DETECT_INST0_ENABLE> RX Timing Detect
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_TIMING_DETECT_INST0_ENABLE 0 //仅测试 打开
// <q SL_RAIL_UTIL_INIT_EVENT_RX_TIMING_LOST_INST0_ENABLE> RX Timing Lost
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_TIMING_LOST_INST0_ENABLE 0 //仅测试 打开
// <q SL_RAIL_UTIL_INIT_EVENT_RX_PREAMBLE_DETECT_INST0_ENABLE> RX Preamble Detect
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_PREAMBLE_DETECT_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_RX_PREAMBLE_LOST_INST0_ENABLE> RX Preamble Lost
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_PREAMBLE_LOST_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_RX_SYNC1_DETECT_INST0_ENABLE> RX Sync1 Detect
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_SYNC1_DETECT_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_RX_SYNC2_DETECT_INST0_ENABLE> RX Sync2 Detect
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_SYNC2_DETECT_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_RX_FILTER_PASSED_INST0_ENABLE> RX Filter Passed
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_FILTER_PASSED_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_RX_ADDRESS_FILTERED_INST0_ENABLE> RX Address Filtered
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_ADDRESS_FILTERED_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_RX_PACKET_RECEIVED_INST0_ENABLE> RX Packet Received
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_PACKET_RECEIVED_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_RX_FRAME_ERROR_INST0_ENABLE> RX Frame Error
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_FRAME_ERROR_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_RX_PACKET_ABORTED_INST0_ENABLE> RX Packet Aborted
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_PACKET_ABORTED_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_RX_TIMEOUT_INST0_ENABLE> RX Timeout
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_TIMEOUT_INST0_ENABLE 1 //接收前先set stateTiming RxResearchTimeout即可产生
// <q SL_RAIL_UTIL_INIT_EVENT_RX_CHANNEL_HOPPING_COMPLETE_INST0_ENABLE> RX Channel Hopping Complete
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_CHANNEL_HOPPING_COMPLETE_INST0_ENABLE 0  //观察自动调频情况，用于debug autoHop开启后的接收失败情况,240304改为0
// <q SL_RAIL_UTIL_INIT_EVENT_RX_DUTY_CYCLE_RX_END_INST0_ENABLE> RX Duty Cycle RX End
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_DUTY_CYCLE_RX_END_INST0_ENABLE 0
// </h>
// <h> TX Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_TX_PACKET_SENT_INST0_ENABLE> TX Packet Sent
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_PACKET_SENT_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_TX_ABORTED_INST0_ENABLE> TX Aborted
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_ABORTED_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_TX_BLOCKED_INST0_ENABLE> TX Blocked
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_BLOCKED_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_TX_STARTED_INST0_ENABLE> TX Started
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_STARTED_INST0_ENABLE 0
// </h>
// <h> RSSI Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_RSSI_AVERAGE_DONE_INST0_ENABLE> RSSI Average Done
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RSSI_AVERAGE_DONE_INST0_ENABLE 0
// </h>
// <h> FIFO Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_RX_FIFO_ALMOST_FULL_INST0_ENABLE> RX FIFO, Almost Full
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_FIFO_ALMOST_FULL_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_RX_FIFO_FULL_INST0_ENABLE> RX FIFO, Full
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_FIFO_FULL_INST0_ENABLE  1
// <q SL_RAIL_UTIL_INIT_EVENT_RX_FIFO_OVERFLOW_INST0_ENABLE> RX FIFO, Overflow
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_FIFO_OVERFLOW_INST0_ENABLE 1
// <q SL_RAIL_UTIL_INIT_EVENT_TX_FIFO_ALMOST_EMPTY_INST0_ENABLE> TX FIFO, Almost Empty
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_FIFO_ALMOST_EMPTY_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TX_UNDERFLOW_INST0_ENABLE> TX FIFO, Underflow
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_UNDERFLOW_INST0_ENABLE 0
// </h>
// <h> CCA Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_TX_CHANNEL_CLEAR_INST0_ENABLE> TX CCA, Channel Clear
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_CHANNEL_CLEAR_INST0_ENABLE 0 //考虑 TX LBT使用该方式
// <q SL_RAIL_UTIL_INIT_EVENT_TX_CHANNEL_BUSY_INST0_ENABLE> TX CCA, Channel Busy
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_CHANNEL_BUSY_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TX_CCA_RETRY_INST0_ENABLE> TX CCA, Retry
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_CCA_RETRY_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TX_START_CCA_INST0_ENABLE> TX CCA, Started
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_START_CCA_INST0_ENABLE 0
// </h>
// <h> Scheduled Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_RX_TX_SCHEDULED_RX_TX_STARTED_INST0_ENABLE> Scheduled RX/TX Started
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_TX_SCHEDULED_RX_TX_STARTED_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_RX_SCHEDULED_RX_END_INST0_ENABLE> Scheduled RX End
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_SCHEDULED_RX_END_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_RX_SCHEDULED_RX_MISSED_INST0_ENABLE> Scheduled RX Missed
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_SCHEDULED_RX_MISSED_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TX_SCHEDULED_TX_MISSED_INST0_ENABLE> Scheduled TX Missed
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_SCHEDULED_TX_MISSED_INST0_ENABLE 0
// </h>
// <h> ACK Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_RX_ACK_TIMEOUT_INST0_ENABLE> RX ACK, Timeout
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_RX_ACK_TIMEOUT_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TXACK_PACKET_SENT_INST0_ENABLE> TX ACK, Packet Sent
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TXACK_PACKET_SENT_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TXACK_ABORTED_INST0_ENABLE> TX ACK, Aborted
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TXACK_ABORTED_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TXACK_BLOCKED_INST0_ENABLE> TX ACK, Blocked
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TXACK_BLOCKED_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TXACK_UNDERFLOW_INST0_ENABLE> TX ACK, FIFO Underflow
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TXACK_UNDERFLOW_INST0_ENABLE 0
// </h>
// <h> Protocol Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_IEEE802154_DATA_REQUEST_COMMAND_INST0_ENABLE> IEEE 802.15.4 Data Request Command
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_IEEE802154_DATA_REQUEST_COMMAND_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_ZWAVE_BEAM_INST0_ENABLE> Z-Wave Beam
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_ZWAVE_BEAM_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_ZWAVE_LR_ACK_REQUEST_COMMAND_INST0_ENABLE> Z-Wave LR ACK Request Command
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_ZWAVE_LR_ACK_REQUEST_COMMAND_INST0_ENABLE 0
// </h>
// <h> Dynamic Multiprotocol (DMP) Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_CONFIG_UNSCHEDULED_INST0_ENABLE> Config Unscheduled
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_CONFIG_UNSCHEDULED_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_CONFIG_SCHEDULED_INST0_ENABLE> Config Scheduled
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_CONFIG_SCHEDULED_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_SCHEDULER_STATUS_INST0_ENABLE> Scheduler Status
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_SCHEDULER_STATUS_INST0_ENABLE 0
// </h>
// <h> Calibration Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_CAL_NEEDED_INST0_ENABLE> Calibration Needed
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_CAL_NEEDED_INST0_ENABLE 0
// </h>
// <h> RSSI Radio Events
// <q SL_RAIL_UTIL_INIT_EVENT_DETECT_RSSI_THRESHOLD_INST0_ENABLE> RSSI detect threshold
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_DETECT_RSSI_THRESHOLD_INST0_ENABLE 0
// </h>
// <h> Thermistor Events
// <q SL_RAIL_UTIL_INIT_EVENT_THERMISTOR_DONE_INST0_ENABLE> End of thermistor measurement
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_THERMISTOR_DONE_INST0_ENABLE 0
// </h>
// <h> Temperature Events
// <q SL_RAIL_UTIL_INIT_EVENT_TX_BLOCKED_TOO_HOT_INST0_ENABLE> Transmit blocked because of temperature limitation
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TX_BLOCKED_TOO_HOT_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TEMPERATURE_TOO_HOT_INST0_ENABLE> Temperature is too hot for Tx operation
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TEMPERATURE_TOO_HOT_INST0_ENABLE 0
// <q SL_RAIL_UTIL_INIT_EVENT_TEMPERATURE_COOL_DOWN_INST0_ENABLE> Temperature has cooled enough for Tx operation
// <i> Default: 0
#define DS_RAIL_UTIL_INIT_EVENT_TEMPERATURE_COOL_DOWN_INST0_ENABLE 0

#define DS_RAIL_UTIL_INIT_EVENT_INST0_MASK (RAIL_EVENTS_NONE              \
  | (DS_RAIL_UTIL_INIT_EVENT_RSSI_AVERAGE_DONE_INST0_ENABLE               \
    ? RAIL_EVENT_RSSI_AVERAGE_DONE : RAIL_EVENTS_NONE)                                 \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_ACK_TIMEOUT_INST0_ENABLE                  \
    ? RAIL_EVENT_RX_ACK_TIMEOUT : RAIL_EVENTS_NONE)                                    \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_FIFO_ALMOST_FULL_INST0_ENABLE             \
    ? RAIL_EVENT_RX_FIFO_ALMOST_FULL : RAIL_EVENTS_NONE)                               \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_PACKET_RECEIVED_INST0_ENABLE              \
    ? RAIL_EVENT_RX_PACKET_RECEIVED : RAIL_EVENTS_NONE)                                \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_PREAMBLE_LOST_INST0_ENABLE                \
    ? RAIL_EVENT_RX_PREAMBLE_LOST : RAIL_EVENTS_NONE)                                  \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_PREAMBLE_DETECT_INST0_ENABLE              \
    ? RAIL_EVENT_RX_PREAMBLE_DETECT : RAIL_EVENTS_NONE)                                \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_SYNC1_DETECT_INST0_ENABLE                 \
    ? RAIL_EVENT_RX_SYNC1_DETECT : RAIL_EVENTS_NONE)                                   \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_SYNC2_DETECT_INST0_ENABLE                 \
    ? RAIL_EVENT_RX_SYNC2_DETECT : RAIL_EVENTS_NONE)                                   \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_FRAME_ERROR_INST0_ENABLE                  \
    ? RAIL_EVENT_RX_FRAME_ERROR : RAIL_EVENTS_NONE)                                    \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_FIFO_FULL_INST0_ENABLE                    \
    ? RAIL_EVENT_RX_FIFO_FULL : RAIL_EVENTS_NONE)                                      \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_FIFO_OVERFLOW_INST0_ENABLE                \
    ? RAIL_EVENT_RX_FIFO_OVERFLOW : RAIL_EVENTS_NONE)                                  \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_ADDRESS_FILTERED_INST0_ENABLE             \
    ? RAIL_EVENT_RX_ADDRESS_FILTERED : RAIL_EVENTS_NONE)                               \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_TIMEOUT_INST0_ENABLE                      \
    ? RAIL_EVENT_RX_TIMEOUT : RAIL_EVENTS_NONE)                                        \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_TX_SCHEDULED_RX_TX_STARTED_INST0_ENABLE   \
    ? RAIL_EVENT_SCHEDULED_RX_STARTED : RAIL_EVENTS_NONE)                              \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_SCHEDULED_RX_END_INST0_ENABLE             \
    ? RAIL_EVENT_RX_SCHEDULED_RX_END : RAIL_EVENTS_NONE)                               \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_SCHEDULED_RX_MISSED_INST0_ENABLE          \
    ? RAIL_EVENT_RX_SCHEDULED_RX_MISSED : RAIL_EVENTS_NONE)                            \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_PACKET_ABORTED_INST0_ENABLE               \
    ? RAIL_EVENT_RX_PACKET_ABORTED : RAIL_EVENTS_NONE)                                 \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_FILTER_PASSED_INST0_ENABLE                \
    ? RAIL_EVENT_RX_FILTER_PASSED : RAIL_EVENTS_NONE)                                  \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_TIMING_LOST_INST0_ENABLE                  \
    ? RAIL_EVENT_RX_TIMING_LOST : RAIL_EVENTS_NONE)                                    \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_TIMING_DETECT_INST0_ENABLE                \
    ? RAIL_EVENT_RX_TIMING_DETECT : RAIL_EVENTS_NONE)                                  \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_CHANNEL_HOPPING_COMPLETE_INST0_ENABLE     \
    ? RAIL_EVENT_RX_CHANNEL_HOPPING_COMPLETE : RAIL_EVENTS_NONE)                       \
  | (DS_RAIL_UTIL_INIT_EVENT_RX_DUTY_CYCLE_RX_END_INST0_ENABLE            \
    ? RAIL_EVENT_RX_DUTY_CYCLE_RX_END : RAIL_EVENTS_NONE)                              \
  | (DS_RAIL_UTIL_INIT_EVENT_IEEE802154_DATA_REQUEST_COMMAND_INST0_ENABLE \
    ? RAIL_EVENT_IEEE802154_DATA_REQUEST_COMMAND : RAIL_EVENTS_NONE)                   \
  | (DS_RAIL_UTIL_INIT_EVENT_ZWAVE_BEAM_INST0_ENABLE                      \
    ? RAIL_EVENT_ZWAVE_BEAM : RAIL_EVENTS_NONE)                                        \
  | (DS_RAIL_UTIL_INIT_EVENT_ZWAVE_LR_ACK_REQUEST_COMMAND_INST0_ENABLE    \
    ? RAIL_EVENT_ZWAVE_LR_ACK_REQUEST_COMMAND : RAIL_EVENTS_NONE)                      \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_FIFO_ALMOST_EMPTY_INST0_ENABLE            \
    ? RAIL_EVENT_TX_FIFO_ALMOST_EMPTY : RAIL_EVENTS_NONE)                              \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_PACKET_SENT_INST0_ENABLE                  \
    ? RAIL_EVENT_TX_PACKET_SENT : RAIL_EVENTS_NONE)                                    \
  | (DS_RAIL_UTIL_INIT_EVENT_TXACK_PACKET_SENT_INST0_ENABLE               \
    ? RAIL_EVENT_TXACK_PACKET_SENT : RAIL_EVENTS_NONE)                                 \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_ABORTED_INST0_ENABLE                      \
    ? RAIL_EVENT_TX_ABORTED : RAIL_EVENTS_NONE)                                        \
  | (DS_RAIL_UTIL_INIT_EVENT_TXACK_ABORTED_INST0_ENABLE                   \
    ? RAIL_EVENT_TXACK_ABORTED : RAIL_EVENTS_NONE)                                     \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_BLOCKED_INST0_ENABLE                      \
    ? RAIL_EVENT_TX_BLOCKED : RAIL_EVENTS_NONE)                                        \
  | (DS_RAIL_UTIL_INIT_EVENT_TXACK_BLOCKED_INST0_ENABLE                   \
    ? RAIL_EVENT_TXACK_BLOCKED : RAIL_EVENTS_NONE)                                     \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_UNDERFLOW_INST0_ENABLE                    \
    ? RAIL_EVENT_TX_UNDERFLOW : RAIL_EVENTS_NONE)                                      \
  | (DS_RAIL_UTIL_INIT_EVENT_TXACK_UNDERFLOW_INST0_ENABLE                 \
    ? RAIL_EVENT_TXACK_UNDERFLOW : RAIL_EVENTS_NONE)                                   \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_CHANNEL_CLEAR_INST0_ENABLE                \
    ? RAIL_EVENT_TX_CHANNEL_CLEAR  : RAIL_EVENTS_NONE)                                 \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_CHANNEL_BUSY_INST0_ENABLE                 \
    ? RAIL_EVENT_TX_CHANNEL_BUSY : RAIL_EVENTS_NONE)                                   \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_CCA_RETRY_INST0_ENABLE                    \
    ? RAIL_EVENT_TX_CCA_RETRY : RAIL_EVENTS_NONE)                                      \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_START_CCA_INST0_ENABLE                    \
    ? RAIL_EVENT_TX_START_CCA : RAIL_EVENTS_NONE)                                      \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_STARTED_INST0_ENABLE                      \
    ? RAIL_EVENT_TX_STARTED : RAIL_EVENTS_NONE)                                        \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_SCHEDULED_TX_MISSED_INST0_ENABLE          \
    ? RAIL_EVENT_TX_SCHEDULED_TX_MISSED : RAIL_EVENTS_NONE)                            \
  | (DS_RAIL_UTIL_INIT_EVENT_CONFIG_UNSCHEDULED_INST0_ENABLE              \
    ? RAIL_EVENT_CONFIG_UNSCHEDULED : RAIL_EVENTS_NONE)                                \
  | (DS_RAIL_UTIL_INIT_EVENT_CONFIG_SCHEDULED_INST0_ENABLE                \
    ? RAIL_EVENT_CONFIG_SCHEDULED : RAIL_EVENTS_NONE)                                  \
  | (DS_RAIL_UTIL_INIT_EVENT_SCHEDULER_STATUS_INST0_ENABLE                \
    ? RAIL_EVENT_SCHEDULER_STATUS : RAIL_EVENTS_NONE)                                  \
  | (DS_RAIL_UTIL_INIT_EVENT_CAL_NEEDED_INST0_ENABLE                      \
    ? RAIL_EVENT_CAL_NEEDED : RAIL_EVENTS_NONE)                                        \
  | (DS_RAIL_UTIL_INIT_EVENT_DETECT_RSSI_THRESHOLD_INST0_ENABLE           \
    ? RAIL_EVENT_DETECT_RSSI_THRESHOLD : RAIL_EVENTS_NONE)                             \
  | (DS_RAIL_UTIL_INIT_EVENT_THERMISTOR_DONE_INST0_ENABLE                 \
    ? RAIL_EVENT_THERMISTOR_DONE : RAIL_EVENTS_NONE)                                   \
  | (DS_RAIL_UTIL_INIT_EVENT_TX_BLOCKED_TOO_HOT_INST0_ENABLE              \
    ? RAIL_EVENT_TX_BLOCKED_TOO_HOT : RAIL_EVENTS_NONE)                                \
  | (DS_RAIL_UTIL_INIT_EVENT_TEMPERATURE_TOO_HOT_INST0_ENABLE             \
    ? RAIL_EVENT_TEMPERATURE_TOO_HOT : RAIL_EVENTS_NONE)                               \
  | (DS_RAIL_UTIL_INIT_EVENT_TEMPERATURE_COOL_DOWN_INST0_ENABLE           \
    ? RAIL_EVENT_TEMPERATURE_COOL_DOWN : RAIL_EVENTS_NONE))

#define DS_FLEX_RAIL_TX_FIFO_SIZE     (256)
#define DS_FLEX_RAIL_RX_FIFO_SIZE     (512)

#define DS_RAIL_UTIL_PA_POWER_DECI_DBM      140

typedef enum sl_rail_util_protocol_type{
  SL_RAIL_UTIL_PROTOCOL_PROPRIETARY, /* use rail_config.c/h */

} sl_rail_util_protocol_type_t;

#define ANT0_PORT   (gpioPortA)
#define ANT0_PIN    (3)

/***************************************** 内部使用宏定义、枚举 *******************************************************/



/***************************************** 外部使用宏定义、枚举*******************************************************/
#if 0
typedef enum
{
    EN_RF_INT_REQ_PREAMEBLE_VALID = 0,
    EN_RF_INT_REQ_PREAMEBLE_TIMEOUT ,
    EN_RF_INT_REQ_SYNC_VALID,
    EN_RF_INT_REQ_SYNC_INVALID,
    EN_RF_INT_REQ_RX_FIFO_ALMOST_FULL,
    EN_RF_INT_REQ_RX_DONE,
    EN_RF_INT_REQ_RX_CRC_ERROR,
    EN_RF_INT_REQ_TX_FIFO_ALMOST_EMPTY,
    EN_RF_INT_REQ_TX_DONE,
    EN_RF_INT_REQ_FIFO_ERROR,
    EN_RF_INT_REQ_OTHER_ERROR,

}RF_INT_E;
#endif

typedef enum //迁移到bsp_rf.h内
{
    EN_MAC_RF_STATE_IDLE = 0, //RF处于idle态
    EN_MAC_RF_STATE_WAIT_PREAMBLE,//RF处于RX态
    EN_MAC_RF_STATE_WAIT_SYNCWORD,//RF处于RX态
    EN_MAC_RF_STATE_RX_PAYLOADING,//RF处于RX态
    EN_MAC_RF_STATE_TX_PAYLOADING,//RF处于TX态

    EN_MAC_RF_STATE_MAX

}MAC_RF_STATE_E;

typedef struct
{
  uint16_t packet_size ;
  uint8_t *start_of_packet ;
  RAIL_RxPacketDetails_t details;
  int16_t AfcError;//单位Hz
}RF_PACKET_ST;

/***************************************** 外部使用宏定义、枚举 *******************************************************/

#define RADIO_CONFIG_ENABLE_IRCAL_MULTIPLE_RF_PATHS 1

typedef void (*railUntilOnEventCallback)(RAIL_Handle_t rail_handle, RAIL_Events_t events);
typedef void (*rfReadyCallback)(RAIL_Handle_t rail_handle);
typedef void (*channelConfigChangeCallback)(RAIL_Handle_t rail_handle, const RAIL_ChannelConfigEntry_t *entry);

void bsp_rail_util_pa_init(void);
void bsp_rail_util_rssi_init(void);

/*此函数用于 rf初始化*/
void rf_init(void);
void bsp_rf_config_chan();
void bsp_set_rf_idle(RAIL_IdleMode_t mode, bool wait);
uint8_t bsp_get_rf_state(void);
MAC_RF_STATE_E getRfState(void);
uint8_t bsp_rf_set_tx_preambleLen(uint16_t Len);
void rxCompleteHandle(void *pFun, uint8_t state, void* pData);
RF_PACKET_ST* getLastRecvPacketPoint();

uint8_t bsp_rf_set_tx_power_bdm(RAIL_TxPower_t power);
int16_t bsp_rf_get_tx_power_bdm(void);

void bsp_rf_reset_fifo(bool txFifo, bool rxFifo);
uint16_t bsp_rf_write_tx_fifo(const uint8_t *dataPtr, uint16_t writeLength, bool reset);
uint8_t bsp_rf_config_rx_option(RAIL_RxOptions_t mask,RAIL_RxOptions_t options);
uint8_t bsp_rf_start_rx(uint16_t channel, const RAIL_SchedulerInfo_t *schedulerInfo);
uint8_t bsp_rf_start_tx(uint16_t channel, RAIL_TxOptions_t options, const RAIL_SchedulerInfo_t *schedulerInfo);

int16_t bsp_rf_get_raw_rssi(bool isWait);//240229改为非阻塞形式，返回单位为1dbm*4，当返回-128*4时，表明不处在接收模式或其他导致未读到的异常
//uint8_t bsp_rf_start_ccaLbt_tx(uint16_t channel, RAIL_TxOptions_t options,  const RAIL_LbtConfig_t *lbtConfig, const RAIL_SchedulerInfo_t *schedulerInfo);
//uint8_t bsp_rf_start_ccaLbt_schedule_tx(uint16_t channel, RAIL_TxOptions_t options, const RAIL_ScheduleTxConfig_t *scheduleTxConfig, const RAIL_LbtConfig_t *lbtConfig, const RAIL_SchedulerInfo_t *schedulerInfo);
uint8_t bsp_rf_start_tx_stream_alt(uint16_t channel, RAIL_StreamMode_t mode, RAIL_TxOptions_t options);
uint8_t bsp_rf_stop_tx_stream(void);
uint8_t bsp_rf_is_channel_valid(uint16_t channel);
uint8_t bsp_rf_set_channel(uint32_t channel);
uint8_t bsp_rf_get_channel( uint16_t *channel);

uint16_t bsp_set_up_tx_fifo(uint8_t *fifo, uint16_t fifi_size);
uint16_t bsp_set_up_rx_fifo(uint8_t *fifo, uint16_t fifi_size);

uint8_t bsp_rf_set_ctune( uint32_t ctune);
uint32_t bsp_rf_get_ctune(void);

uint8_t bsp_rf_rx_channel_hopping_enable(bool enable, bool reset);

uint8_t bsp_rf_set_hop_main_chan(uint8_t mainChan);
uint8_t bsp_rf_get_hop_main_chan();
uint8_t bsp_rf_set_hop_resync_chan(uint8_t resyncChan);
uint8_t bsp_rf_get_hop_resync_chan();

int16_t bsp_rf_get_hop_main_chan_rssi();
int16_t bsp_rf_get_hop_resync_chan_rssi();
void bsp_rf_cw(uint8_t chan);
uint8_t bsp_rf_tx_transition_set(RAIL_RadioState_t successState, RAIL_RadioState_t errorState);
uint8_t bsp_rf_rx_transition_set(RAIL_RadioState_t successState, RAIL_RadioState_t errorState);

int8_t bsp_rf_rssi_get(void);

bool bsp_rf_antenna_diversity_feature_get(void);
uint8_t bsp_rf_config_antenna(const RAIL_AntennaConfig_t *config);
void bsp_rf_antenna_select(uint8_t ante);

#endif /* BSP_RF_H_ */
